package com.hbmcc.rxjava.test

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import com.hbmcc.rxjava.R
import com.hbmcc.rxjava.databinding.ViewTestItemBinding
import com.hbmcc.rxjava.databinding.ViewTestTitleBinding

/**
 * 创建日期：2020/11/13
 * 描述:Test的列表
 * 作者:支豪亮
 */
class ProxyTestAdapter(private val list: MutableList<MethodBean>, private val iMethodCallback: IMethodCallback) :
    DelegateAdapter.Adapter<RecyclerView.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
        return if (viewType == R.layout.view_test_title) {
            TitleViewHolder(ViewTestTitleBinding.bind(itemView))
        } else {
             ItemViewHolder(ViewTestItemBinding.bind(itemView))
        }
    }

    override fun onBindViewHolder(
        holder: RecyclerView.ViewHolder,
        position: Int,
        payloads: MutableList<Any>
    ) {
        super.onBindViewHolder(holder, position, payloads)
    }
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is TitleViewHolder) {
             holder.binding.methodBean = list[position]
            holder.binding.methodCallback = iMethodCallback
        } else if (holder is ItemViewHolder) {
            holder.binding.methodBean = list[position]
            holder.binding.methodCallback = iMethodCallback
        }
    }

    override fun getItemCount() = list.size


    override fun onCreateLayoutHelper(): LayoutHelper {
        return LinearLayoutHelper()
    }

    override fun getItemViewType(position: Int): Int {
        return list[position].layout
    }


    class TitleViewHolder(val binding: ViewTestTitleBinding) : RecyclerView.ViewHolder(binding.root)


    class ItemViewHolder(var binding: ViewTestItemBinding) : RecyclerView.ViewHolder(binding.root)


}